//
//  LightBaseViewController.m
//  Blue-toothLight
//
//  Created by mazg on 15/6/20.
//  Copyright (c) 2015年 mazg. All rights reserved.
//

#import "LightBaseViewController.h"
#import "LightTabViewController.h"
#import "LightModel.h"
#import "NSManagedObject+helper.h"


@interface LightBaseViewController ()

@end

@implementation LightBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //2、创建颜色操作模块
    _colorInstance=[OperationColor shareOperationColorInstance];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)closeAction:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)toggleOpenAction:(id)sender {
    
    UIButton *btn=sender;
    btn.selected=!btn.selected;
    
    LightTabViewController *lightTab=(LightTabViewController *)self.tabBarController;
    for (LightModel *model in lightTab.currentLightList) {
        for (CBPeripheral *cbp in lightTab.allConnectedPerArr) {
            if ([cbp.identifier.UUIDString isEqualToString:model.perIdentifier]) {
                if ([model.isOpen boolValue]) {
                    [_colorInstance turnOffLightWithPeripheral:cbp];
                    self.selColor=model.perColor;
                }
                else{
                    [_colorInstance openLightWithPeripheral:cbp];
                }
            }
        }
    }
}


-(NSArray *)getCurrentPeripheralArr{
    LightTabViewController *lightTab=(LightTabViewController *)self.tabBarController;
    NSMutableArray *arrM=[[NSMutableArray alloc]init];
    for (LightModel *model in lightTab.currentLightList) {
        for (CBPeripheral *cbp in lightTab.allConnectedPerArr) {
            if ([cbp.identifier.UUIDString isEqualToString:model.perIdentifier]) {
                [arrM addObject:cbp];
            }
        }
    }
    return arrM;
}


@end
